﻿using System;
using System.Collections.Generic;
using System.Linq;

using System.IO;
using Newtonsoft.Json;

namespace SteamMoverWPF
{
    public class SteamMoverConfig : JSONConfig.JSONDictionary
    {
        [JsonIgnore]
        public FileInfo Path { get; private set; }
        
        public List<String> AlternateLocations { get; private set; }
        public List<String> MainLocations { get; private set; }
        public int CrawlDepth { get; private set; }
        public string SteamExeName { get; private set; }

        public SteamMoverConfig(String path) : base()
        {
            this.Path = new FileInfo(path);
        }

        public void LoadJSON() 
        {
            var text = File.ReadAllText(Path.FullName);

            try
            {
                _innerDictionary = LoadConfig(text);

                AlternateLocations = GetCustomClass<String[]>("AlternateLocations").ToList();
                MainLocations = GetCustomClass<String[]>("MainLocations").ToList();
                CrawlDepth = GetInt("CrawlDepth") ?? 5;
                SteamExeName = GetString("SteamExeName") ?? "Steam.exe";

            }
            catch (Exception ex)
            {

            }
        }

        public void SaveJSON()
        {
            try
            {
                var jsonFile = JsonConvert.SerializeObject(this, Formatting.Indented);

                File.WriteAllText(Path.FullName, jsonFile);
            }
            catch (Exception ex)
            {

            }
        }
    }
}
